<?php

App::uses('Controller', 'AppController');

class AdminAppController extends AppController {
	
	public $uses = array("Administrator");
	
	public $components = array (
		'Session',
		'Auth' => array (
			'loginRedirect'  => '/admin/dashboard',
			'logoutRedirect' => '/admin/login',
			'loginAction' => '/admin/login'
		),
		'Admin.Upload'
	);
	
	public $helpers = array('Html', 'Form', 'Session', 'Text');
	
	public function beforeFilter() {
		parent::beforeFilter();
		// Load Settings
		Configure::load("Admin.settings");
		// Auth Config
		$this->Auth->authenticate = array(
			AuthComponent::ALL => array(
				'userModel' => 'Administrator', 
				'fields' => array('username' => 'email')
			),
			'Form'
		);
	}
	
	public function beforeRender() {
		parent::beforeRender();
		// set global variables for views
		$this->set('referer', $this->referer());
		$this->set('appName', Configure::read('CMS.settings.app_name'));
		$this->set('jQueryUITheme', Configure::read('CMS.settings.jquery-ui-theme'));
		$this->set('logged', $this->Auth->loggedIn());
		$this->set("modules", Configure::read("CMS.modules"));
	}
	
	public function setUserInfo($message, $type = 'info') {
		$this->Session->setFlash( $message, 'flash', array('type' => $type) );
	}
	
}